package com.smartwebee.android.blespp.hospital.adapter;

import android.content.Context;
import android.databinding.DataBindingUtil;
import android.view.View;
import android.view.ViewGroup;

import com.smartwebee.android.blespp.R;
import com.smartwebee.android.blespp.bean.ItemBean;
import com.smartwebee.android.blespp.databinding.AdapterItemBinding;
import com.smartwebee.android.blespp.eventbusclass.AddPlanEvent;
import com.smartwebee.android.blespp.hospital.HospitalBaseAdapter;
import com.smartwebee.android.blespp.utils.UIUtils;
import com.smartwebee.android.blespp.utils.Utils;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

/**
 * Created by steward on 2018/7/5.
 */

public class ItemAdapter extends HospitalBaseAdapter<ItemBean> {

    public ItemAdapter(Context context, List<ItemBean> datas) {
        super(context, datas);
    }

    @Override
    protected View initView(final int position, View convertView, ViewGroup parent) {
        AdapterItemBinding binding = null;
        if (convertView == null) {
            binding = DataBindingUtil.inflate(inflater, R.layout.adapter_item, parent, false);
            convertView = binding.getRoot();
            convertView.setTag(binding);
        } else {
            binding = (AdapterItemBinding) convertView.getTag();
        }
        binding.tvName.setText(Utils.getModeName(datas.get(position).getTitle()));
        binding.tvDesc.setText(getItem(position).getDesc());
        binding.imgIntro.setImageResource(datas.get(position).getImgId());
        binding.btnAddToPlan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                UIUtils.showSelectPlans(context, new UIUtils.DialogClickEvent() {
                    @Override
                    public void click(int mPosition) {
                        EventBus.getDefault().post(new AddPlanEvent(getItem(position), mPosition));
                    }
                });
            }
        });
        return convertView;
    }
}
